package mode.decoratorMode06;

import java.util.ArrayList;
import java.util.Objects;

/**
 * 06 装饰者模式
 * 定义：动态的将新功能附加到对象上。在对象功能扩展方面，它比继承更有弹性。
 *
 * https://blog.csdn.net/m0_47944994/article/details/127901010
 *
 *
 */
public class DecoratorPatternDemo {

    public static void main(String[] args) {
        FastFood food = new FriedRice();

        //花费的价格
        System.out.println(food.getDesc() + " " + food.cost() + "元");

        System.out.println("========");

        //点一份加鸡蛋的炒饭
        FastFood food1 = new FriedRice();
        food1 = new Egg(food1);

        //花费的价格
        System.out.println(food1.getDesc() + " " + food1.cost() + "元");
        System.out.println("========");

        //点一份加培根的炒面
        FastFood food2 = new FriedNoodles();
        food2 = new Bacon(food2);

        //花费的价格
        System.out.println(food2.getDesc() + " " + food2.cost() + "元");
        System.out.println("==  ....... ======");



        ArrayList<? super FastFood> foodList = new ArrayList<>();

        foodList.add(food);
        foodList.add(food1);
        foodList.add(food2);

        for (Object item : foodList){

            FastFood foodItem = (FastFood) item;

            System.out.println(foodItem.getDesc() + " " + foodItem.cost() + "元");
        }





    }

}


//  炒饭 10.0元
//  ========
//  鸡蛋炒饭 11.0元
//  ========
//  培根炒面 14.0元
